Ext.define('AM.view.modules.westMenu.NorthPanelScope', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.northPanelScope',
    
    title: false,
    // border: false,
    height: 75,
    layout: 'fit',
    bodyStyle: 'backgroud:#99BCE8',
	//html: '<div class="header"><div class="logo"></div><div class="logoSystem"><img src="./skin/green/images/logoSystem2.gif" /></div><div class="user"><span class="loginMessage">您好，<span id="userName" style="color: blue;text-decoration:underline; cursor: pointer;"></span>，欢迎您登录招聘管理系统</span><span class="btnBG quitBtn"><a style="cursor: pointer" onclick="logOut();">注销</a></span></div></div>',
	
    initComponent: function(){
        
		var html = '';
        //		<!--顶部菜单-->
        html += '<div>';
        html += '<table border="0" cellspacing="0" cellpadding="0"  class="header">';
        html += '  <tr>';
        html += '    <td height="70" align="left"><table width="0" border="0" cellspacing="0" cellpadding="0">';
        html += '        <tr>';
        html += '          <td><!--logo2-->';
        html += '            <div class="logoSystem"></div></td>';
        html += '        </tr>';
        html += '      </table></td>';
        html += '    <td height="70"><!--右侧栏目-->';
        html += '      <div class="rightColumn" style="float:none;display:block;width:auto;">';
        html += '        <div class="contextMenu"> ';
        html+='          <table style="float:right"><tr>';
        
        
        html += '			<td><select id="selectRole" style="margin-left: 10px;">';
        html += '				<option>'+modules_lang.selectRole+'</option>';
        html += '			</select></td>';
        
        html += '			<td><select  name="selectScope" id="selectScope" style="margin-left: 10px;width:130px">';
        html += '				<option>'+modules_lang.selectScope+'</option>';
        html += '			</select></td>';
       
        html += '          <td><a onclick="logOut();" href="#" style="margin-left:10px;width:35px;height:26px;">';
        html+='  				<img src="./skin/red/images/quitBtn.gif" alt="'+modules_lang.loginMessage[4]+'"  style="margin-right:20px;width:35px;height:26px;"/></a></td>';
        html+='</tr>';
        html+='</table>';
        html += '        </div>';
        html += '      </div></td>';
        html += '  </tr>';
        html += '  <tr>';
        html += '    <td height="29" colspan="2"><!--导航菜单-->';
        html += '      </div></td>';
        html += '  </tr>';
        html += '</table>';
        html += '</div>';
        this.html = html;
		
        this.callParent(arguments);
    },
	
    
    selectRole: function(eObj, elm, obj){
        var me = this;
        
        if (Ext.isIE) {
            // IE浏览器需要使用dom创建，否则option创建不成功(仅IE8测试不成功，其他不确定)
            // 会降低性能
            Ext.DomHelper.useDom = true;
        }
		
        var selectScopeElm = Ext.get("selectScope");
        //var value = elm.value;
        var value = obj;
        //alert(value);
        var opt = selectScopeElm.select("option");
        opt.each(function(optElm){
            optElm.remove();
        });
        Ext.Ajax.request({
			//url: 'workbench/orchid/data/selectRoleList.jsons',//Demo
//            url: "findScopeList.json",
			url: findScopeUrl,
            params: {
                roleCode: value
            },
            success: function(response){
                var data = response.responseText;
                var json = Ext.decode(data, true);
                //先判断是否为IE浏览器
                //if (Ext.isIE) {
                    // IE浏览器需要使用dom创建，否则option创建不成功(仅IE8测试不成功，其他不确定)
                    // 会降低性能
                    //Ext.DomHelper.useDom = true;
                //}
                //后创建这句话当选项生成  
                var defaultOption = selectScopeElm.createChild({
                    tag: 'option',
                    value: "",
                    html: modules_lang.selectScope
                }, null, true);
                if (json.success) {
                    if (Ext.isIE) {
                        // IE浏览器需要使用dom创建，否则option创建不成功(仅IE8测试不成功，其他不确定)
                        // 会降低性能
                       Ext.DomHelper.useDom = true;
                    }
                    var selectOption = selectScopeElm.createChild(json.data, null, true);
                    if(Ext.isIE){
                    	if (json.data.length == 1) {
                            me.selectScope("", selectScopeElm.dom, selectScopeElm.dom[0].value);
                            selectScopeElm.dom[0].setAttribute("selected", "selected");
                        }
                    }else{
                    	if (json.data.length == 1) {
                    		me.selectScope("", selectScopeElm.dom, selectScopeElm.dom[1].value);
                    		selectScopeElm.dom[1].setAttribute("selected", "selected");
                    	}
                    	else {
                    		selectScopeElm.dom[0].setAttribute("selected", "selected")
                    	}
                    }
					Ext.DomHelper.useDom = false;
                }
            }
        });
        var westTree = Ext.getCmp("westTree");
        westTree.buildMenu(value, "");
        var tabPanel = Ext.getCmp("viewTab");
        var tab = tabPanel.down("#welcome");
        var tabLen = tabPanel.items.items.length;
        for (var i = tabLen - 1; i >= 0; i--) {
            if (tabPanel.items.items[i].itemId != "welcome") {
                var tabc = tabPanel.items.items[i];
                tabPanel.remove(tabc);
            }
        }
		//Ext.DomHelper.useDom = false;
    },
    selectScope: function(eObj, elm, obj){
		if (Ext.isIE) {
            // IE浏览器需要使用dom创建，否则option创建不成功(仅IE8测试不成功，其他不确定)
            // 会降低性能
            Ext.DomHelper.useDom = true;
        }
        var selectRoleElm = Ext.get("selectRole");
        //var value = elm.value;
        var value = obj;
        var roleVal = selectRoleElm.getValue();
        //if (value == "") {
        //  return;
        //}
        //Ext.DomHelper.useDom = false;
        var westTree = Ext.getCmp("westTree");
        westTree.buildMenu(roleVal, value);
        var tabPanel = Ext.getCmp("viewTab");
        var tab = tabPanel.down("#welcome");
        var tabLen = tabPanel.items.items.length;
        for (var i = tabLen - 1; i >= 0; i--) {
            if (tabPanel.items.items[i].itemId != "welcome") {
                var tabc = tabPanel.items.items[i];
                tabPanel.remove(tabc);
            }
        }
		Ext.DomHelper.useDom = false;
    },
    listeners: {
        render: function(){
            var me = this;
			
            if (Ext.isIE) {
                // IE浏览器需要使用dom创建，否则option创建不成功(仅IE8测试不成功，其他不确定)
                // 会降低性能
                Ext.DomHelper.useDom = true;
            }
			Ext.DomHelper.useDom = false;
            var selectRoleElm = Ext.get("selectRole");
            var selectScopeElm = Ext.get("selectScope");
            Ext.Ajax.request({
                 url: findRoleUrl,
                method: "POST",
                success: function(response){
                    var data = response.responseText;
                    var json = Ext.decode(data, true);
                    if (json.success) {
                        if (Ext.isIE) {
                            // IE浏览器需要使用dom创建，否则option创建不成功(仅IE8测试不成功，其他不确定)
                            // 会降低性能
                            Ext.DomHelper.useDom = true;
                        }
                        var selectOption = selectRoleElm.createChild(json.data, null, true);
                        if (json.data.length == 1) {
                            me.selectRole("", selectRoleElm.dom, selectRoleElm.dom[1].value);
                            selectRoleElm.dom[1].setAttribute("selected", "selected");
                        }else{
							selectRoleElm.dom[0].setAttribute("selected", "selected");
						}
						Ext.DomHelper.useDom = false;
                    }
                }
            });
            selectRoleElm.on("change", function(eObj, elm, obj){
                me.selectRole(eObj, elm, eObj.getTarget().value);
            });
            selectScopeElm.on("change", function(eObj, elm, obj){
                me.selectScope(eObj, elm, eObj.getTarget().value);
            });
			//Ext.DomHelper.useDom = false;
        }
    }

});
